﻿using System;
using System.Collections.Generic;
using Tao.OpenGl;

namespace OhioState.Graphics.OpenGL
{
    internal class ModelGL : IDrawable
    {
        public ModelGL(float[] vertices, float[] textureCoords) //, int[] indices)
        {
            this.vertices = vertices;
            this.textureCoords = textureCoords;
            //this.indices = indices;
        }

        #region IDrawable Members
        public IBoundingVolume BoundingVolume
        {
            get;
            private set;
        }

        public IMaterial Material
        {
            get;
            set;
        }

        public void Render(IRenderPanel panel)
        {
            this.Material.MakeActive(panel);
            //Gl.glPointSize(2.4f);
            //Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);

            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, vertices);
            Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, textureCoords);

            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, vertices.Length / 3);
            //Gl.glDrawElements(Gl.GL_TRIANGLES, indices.Length, Gl.GL_UNSIGNED_INT, indices);

            Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            //Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
            this.Material.Deactivate(panel);
        }
        #endregion

        #region Member variables
        float[] vertices;
        float[] textureCoords;
        //int[] indices;
        #endregion
    }
}
